package com.youngball.web.controller;

import com.github.pagehelper.PageInfo;
import com.wordnik.swagger.annotations.ApiModel;
import com.wordnik.swagger.annotations.ApiOperation;
import com.youngball.entity.SysTest;
import com.youngball.service.SysTestService;
import com.youngball.web.webconfig.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Created by liaopingzhu on 2016/11/5.
 */
@Controller
@RequestMapping(value = "/ceshi")
@ApiModel("swagger测试")
public class TestController extends BaseController{

    @Autowired
    private SysTestService sysTestService;

    @ApiOperation(value = "测试",httpMethod = "GET")
    @RequestMapping(value = "/test",method = {RequestMethod.GET},headers = "Accept=application/json")
    public ResponseEntity<Map> test(){
        Map map = new HashMap();
        map.put("data",1);
        map.put("msg","success");
        return bulidResult(map);
    }

    @RequestMapping(value = "findAll",method = {RequestMethod.GET},headers = "Accept=application/json")
    public ResponseEntity<Map> findAll(@RequestParam(required = true, value = "pageIndex") int pageIndex,
                                       @RequestParam(required = true, value = "pageSize") int pageSize){
        Map param = assembledParameter(pageIndex,pageSize);
        PageInfo<SysTest> list = sysTestService.findAll(param);
        LinkedHashMap<String,Object> pagination = assembledPagination(list.getPageNum(),
                list.getPageSize(), list.getTotal());
        //组织结果集
        Map result = new LinkedHashMap();
        result.put("pagination",pagination);
        result.put("list",list.getList());
        return bulidResult(result);
    }

}
